package com.test.wog.controller;

import com.test.wog.service.RouteService;
import com.test.wog.util.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 *路径规划的Controller层
 *
 * @author linxun@buaa.edu.cn
 * @since 2020-02-01
 */
@Api(value = "路径规划Controller", tags = {"冬奥会多模式交通路径规划接口"})
@RestController
public class RouteController {
    @Autowired
    RouteService rs;
    @Autowired
    DateUtil du;

    @ApiOperation(value = "路径规划", notes = "按照起点、终点、出发/到达时间、人员类型进行路径规划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sName", value = "出发点名称", required = false, defaultValue = "延庆汽车站", paramType = "query"),
            @ApiImplicitParam(name = "eName", value = "终点名称", required = false, defaultValue = "国家高山滑雪中心", paramType = "query"),
            @ApiImplicitParam(name = "sLon", value = "出发点经度", required = false, defaultValue = "115.985279", paramType = "query"),
            @ApiImplicitParam(name = "sLat", value = "出发点纬度", required = false, defaultValue = "40.46178", paramType = "query"),
            @ApiImplicitParam(name = "eLon", value = "终点经度", required = false, defaultValue = "115.812538791233", paramType = "query"),
            @ApiImplicitParam(name = "eLat", value = "终点纬度", required = false, defaultValue = "40.547402615018", paramType = "query"),
            @ApiImplicitParam(name = "sTime", value = "出发或到达时间", required = true, defaultValue = "2020-02-15 08:00:00", paramType = "query"),
            @ApiImplicitParam(name = "timeType", value = "时间类型：arrival或set_out", required = true, defaultValue = "arrival", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "人员类型", required = true, defaultValue = "运动员", paramType = "query")
    })
    @RequestMapping(value = "/getRoute", method = RequestMethod.GET)
    @ResponseBody
    public String getRoute(
            @RequestParam(value = "sLon",required = false) Double sLon,
            @RequestParam(value = "sLat",required = false) Double sLat,
            @RequestParam(value = "eLon",required = false) Double eLon,
            @RequestParam(value = "eLat",required = false) Double eLat,
            @RequestParam(value = "sName",required = false) String sName,
            @RequestParam(value = "eName",required = false, defaultValue = "国家高山滑雪中心") String eName,
            @RequestParam(value = "sTime",required = true) String sTime,
            @RequestParam(value = "timeType",required = true, defaultValue = "arrival") String timeType,
            @RequestParam(value = "type",required = true) String type
            ) throws ParseException {
        //第一种情况，输入起始经纬度和终点名称
        String res = "{}";
        /*输入起点经纬度和终点名称*/
        if(sLon != null && sLat != null && eName != null){
            //时间代表到达时间
            if(timeType.equals("arrival")) {
                res = rs.getFinalRoute(sLon, sLat, eName, sTime, type);
            }
            //时间代表出发时间
            else if(timeType.equals("set_out")){

            }
        }
        /*根据起点和终点的名字规划路径*/
        else if(sName != null && eName != null){
            res = rs.getFinalRoute(sName, eName, sTime, type);
        }
        return res;
    }
}
